package com.carlyang.jspservlet.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.carlyang.jspservlet.model.User;

public class UserDao {
	
	public User login(Connection con,User user)throws Exception {
		User resultUser = null;
		//设置查询语句，查询传入得user的用户名和密码是否在数据库中有记录
		String sql = "select * from t_user where userName=? and password=?";
		PreparedStatement pstmt = con.prepareStatement(sql);
		pstmt.setString(1, user.getUserName());
		pstmt.setString(2, user.getPassword());
		ResultSet rs = pstmt.executeQuery();//查询数据库
		if (rs.next()) {
			resultUser = new User();
			resultUser.setUserName(rs.getString("userName"));
			resultUser.setPassword(rs.getString("password"));
		}
		return resultUser;
	}
	
	public void logout() {
		
	}
}
